package main

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

type UserInfo struct {
	Id   int
	Name string
	Age  int
	Addr string
}
type UserProfile struct {
	Id       int
	Pic      string
	CPic     string
	Phone    string
	UserInfo UserInfo `gorm:"ForeignKey:UId;AssociationForeignKey:Id"` //关联关系
	UId      int      //默认关联字段UserID
}

func main() {
	db, err := gorm.Open("mysql", "root:root@tcp(127.0.0.1:3306)/db01?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		panic(err)
	}
	db.AutoMigrate(&UserInfo{}, &UserProfile{})
	defer db.Close()
}
